﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Pikapika.Models;

namespace Pikapika.Controllers
{
    public class TagController : Controller
    {
        [HttpPost]
        public ActionResult Add(int id, string content)
        {
            if (content != null)
            {
                content = content.Trim();
            }
            if (string.IsNullOrEmpty(content))
            {
                return this.HttpBadRequest();
            }
            using (var ctx = new PikapikaDBEntities())
            {
                try
                {
                    ctx.AddToNovelTags(new NovelTag { NovelId = id, Tag = content });
                    ctx.SaveChanges();
                }
                catch (Exception)
                {
                    return this.HttpBadRequest();
                }
            }
            return new HttpStatusCodeResult(200, "OK");
        }

    }
}
